﻿using System;
using System.Collections.Generic;
using System.Text;
using GroupChat2013.Entity;
using GroupChat2013.Service;
using System.IO;
using GroupChat2013.Common;

namespace GroupChat2013.Logic
{
    /// <summary>
    /// 主面板配置按钮解析类
    /// </summary>
    public class MainButtonConfigParse : BaseConfigParse
    {
        /// <summary>
        /// 解析
        /// </summary>
        /// <returns>按钮信息数组</returns>
        public override List<ButtonConfigInfo> Parse()
        {
            Dictionary<string, ButtonConfigInfo> dic = ServiceUrlProxy.GetInstance().GetMainButtonConfig();

            List<ButtonConfigInfo> configList = new List<ButtonConfigInfo>();
            if (dic != null && dic.Values.Count > 0)
            {
                foreach (var kv in dic)
                {
                    DownLoadButtonImage(kv.Value);

                    if (string.IsNullOrEmpty(kv.Value.addr))
                        kv.Value.link = string.Format("http://{0}{1}", ServiceUrlProxy.GetInstance().m_BaseUrl, kv.Value.link);
                    else
                        kv.Value.link = string.Format(kv.Value.addr, kv.Value.link);

                    kv.Value.name = kv.Key;

                    configList.Add(kv.Value);
                }
            }

            return configList;
        }
    }
}
